/*
 * @lc app=leetcode.cn id=442 lang=cpp
 *
 * [442] 数组中重复的数据
 */

// @lc code=start
class Solution
{
public:
  vector<int> findDuplicates(vector<int>& nums)
  {
    vector<int> ans;
    nums.push_back(-1);
    int n = nums.size();
    for (int i = 0; i < n; ++i) {
      int tmp = std::abs(nums[i]);
      if (nums[tmp] > 0) {
        nums[tmp] = -nums[tmp];
      }
      else {
        ans.push_back(nums[i]);
      }
    }

    return ans;
  }
};
// @lc code=end
